﻿CREATE PROCEDURE [dbo].[spObtenDireccionCP]
	@psCodigoPostal VARCHAR(20),
	@pnIdEstado		INT,
	@pnIdMunicipio	INT,
	@pnIdColonia	INT
AS
BEGIN
	IF @psCodigoPostal IS not NULL
	BEGIN
		SELECT	IdEstado, IdMunicipio, IdColonia, CodigoPostal
		FROM	CatColonia
		WHERE	CodigoPostal = @psCodigoPostal
	END
	ELSE
	BEGIN
		SELECT	CodigoPostal
		FROM	CatColonia
		WHERE	IdColonia = @pnIdColonia
		AND		IdEstado  = @pnIdEstado
		AND		IdMunicipio = @pnIdMunicipio
	END
END